import request from '@/utils/request'
// 从配置中获取业务的地址
import { baseUrlConfig } from '@/config/config'
export const basePath = baseUrlConfig.businessBaseUrl
const fastPath = baseUrlConfig.fastUrl
export interface PageListType {
  pageNum?: number
  pageSize?: number
  condition: {
    name: string
    idCard: string
    createTimeEnd: string
    createTimeStart: string
    order: string[]

  }
}

// 新增类型
export interface greylistaddType {
  age: number,
  mender: {
    id: number,
    name: string,
    organId: number,
    organName: string
  },
  files: [
    {
      enclosureCode: string,
      enclosureContent: string,
      enclosureName: string,
      enclosureSuffix: string,
      resourceAddress: string
    }
  ],
  sex: string,
  idCard: string,
  name: string,
  owner: {
    id: number,
    name: string,
    type: string
  },
  typeId: number
}

// 单项删除类型
export interface greylistdelType {
  id: number,
  mender: {
    id: number,
    name: string,
    organId: string,
    organName: string
  }
}

// 批量删除类型
export interface greyListsdelType {
  idList: number[],
  mender: {
    id: number,
    name: string,
    organId: number,
    organName: string
  }
}

// 编辑类型
export interface greylisteditType {
  age: number,
  files: [
    {
      enclosureCode: string,
      enclosureContent: string,
      enclosureName: string,
      enclosureSuffix: string,
      resourceAddress: string
    }
  ],
  sex: string,
  id: number,
  idCard: string,
  mender: {
    id: number,
    name: string,
    organId: number,
    organName: string
  },
  name: string
}

// 获取分页列表
export const greyPageList: (data: PageListType) => Promise<[]> = (
  data: PageListType
) => {
  return request({
    url: basePath + '/pax/grey/find/page',
    method: 'post',
    data
  })
}

// 新增
export const greyListAdd = (data: greylistaddType) => {
  return request({
    url: basePath + '/pax/grey/append',
    method: 'post',
    data
  })
}

// 删除
export const greyListDel = (data: greylistdelType) => {
  return request({
    url: basePath + '/pax/grey/delete',
    method: 'post',
    data
  })
}

// 批量删除
export const greylistDels = (data: greyListsdelType) => {
  return request({
    url: basePath + '/pax/grey/batch/delete',
    method: 'post',
    data
  })
}

// 上传文件
export const uploadFiles = (data: any) => {
  return request({
    url: fastPath + '/fast/uploadFile',
    method: 'post',
    data
  })
}

// 下载文件
export const downloadFiles = (data: any) => {
  return request({
    url: fastPath + `/fast/downloadFile?enclosureCode=${data}`,
    method: 'get',
    responseType: 'blob',
    data
  })
}

// 删除文件
export const deleteFiles = (data: any) => {
  return request({
    url: fastPath + `/fast/deleteFile?enclosureCode=${data}`,
    method: 'get',
    data
  })
}


// 编辑
export const greyListEdit = (data: greylisteditType) => {
  return request({
    url: basePath + '/pax/grey/update',
    method: 'post',
    data
  })
}

// 灰名单种类查询
export const greyTypeList = (data: any) => {
  return request({
    url: basePath + '/pax/grey/type/find',
    method: 'post',
    data
  })
}
